package weibo4j.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class WeiboConfig {
	public WeiboConfig(){}
	private static Properties props = new Properties(); 
	private static File file;
	static{
		try {
			file = new File("config.properties");
			System.out.println("config.properties");
			if( ! file.exists()){
				System.out.println("nnnnnnnnnnnnno");
				props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
				file.createNewFile();
				props.store(new FileWriter(file), "new token");
			} 
			props.load(new FileReader(file));
			System.out.println("nnnnnnnnnnnnno:" + file.getAbsolutePath());
			System.out.println("nnnnnnnnnnnnno:" + props.entrySet().size());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String getValue(String key){
		return props.getProperty(key);
	}

    public static void updateProperties(String key,String value) {    
            props.setProperty(key, value); 
            try {
				props.store(new FileWriter(file), "new token");
			} catch (IOException e) {
				e.printStackTrace();
			}
    } 
}
